package leetcode20210928;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LUYAO
 * Date: 2021-09-28
 * Time: 15:10
 */

import java.util.Stack;


 //Definition for singly-linked list.
 public class ListNode {
    int val;
    ListNode next;
    ListNode(int x) { val = x; }
 }

class Solution2 {
    public int[] reversePrint(ListNode head) {
        Stack<ListNode> stack = new Stack<>();
        ListNode temp = head;
        while(temp != null){
            stack.push(temp);
            temp = temp.next;
        }

        int a = stack.size();
        int[] print = new int[a];
        for (int i = 0; i < a; i++) {
            print[i] = stack.pop().val;

        }

        return print;

    }
}

